//
//  QCTabBarViewController.swift
//  MM
//
//  Created by liujianlong on 2022/8/1.
//

import UIKit
import TCCKit
let offx = CGFloat(16)
let offy = CGFloat(5)
class QCTabBarViewController: UITabBarController {
    var item_layer_arr = [CALayer]()
    override func viewDidLoad() {
        super.viewDidLoad()
        self.delegate = self
        self.setupColor()
        self.setupViewController()
        self.selectedIndex = 1
    }
    
    func setupColor()
    {
        self.tabBar.tintColor = "#FFFFFF".color()
        self.tabBar.unselectedItemTintColor = "#808183".color()
        let bgcolor = "#161718".color()
        if #available(iOS 13, *) {
            let appearance = self.tabBar.standardAppearance.copy()
            //appearance.shadowImage = UIImage.withColor(bgcolor)///设置阴影
            appearance.shadowColor = bgcolor/////设置阴影
            appearance.backgroundImage = UIImage.withColor(bgcolor)
            appearance.backgroundColor = bgcolor
            appearance.backgroundEffect = nil
            self.tabBar.standardAppearance = appearance
            if #available(iOS 15.0, *) {
                ///用这个方法的，这个一定要加，否则15.0系统下会出问题，一滑动tabbar就变透明!!!
                self.tabBar.scrollEdgeAppearance = appearance
            } else {}
        }
    }
    
    func setupViewController()
    {
        let controllers = [QCHomeViewController(), QCControlViewController(),QCSettingViewController()]
        let titles = ["AIR","控制","设置"]
        let imgs = ["AIR","控制","设置"]
        let selectImgs = ["AIR_select","控制_select","设置_select"]
        for i in 0..<controllers.count{
            let vc = controllers[i]
            vc.tabBarItem = UITabBarItem()
            vc.tabBarItem.title = LS(titles[i])
            vc.tabBarItem.image = UIImage(named:imgs[i])?.withRenderingMode(.alwaysOriginal)
            vc.tabBarItem.selectedImage = UIImage(named:selectImgs[i])?.withRenderingMode(.alwaysOriginal)
            let nav = QCNavigationController(rootViewController:vc)
            nav.navigationBar.isHidden = true
            self.addChild(nav)
        }
    }
}

// MARK: - UITabBarControllerDelegate
extension QCTabBarViewController: UITabBarControllerDelegate
{
    func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
        return true
    }
    
    func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
    }
}
